<?php

if (!defined('IN_AJAX')) die(basename(__FILE__));

global $userdata, $lang;

$mode = (string) $this->request['mode'];
$topic_id  = (int) $this->request['topic_id'];

$tor = DB()->fetch_row(" SELECT tor.poster_id, tor.forum_id, tor.attach_id, tor.call_seed_time, tor.complete_count, t.topic_title, f.forum_name, sn.seeders
		FROM ". BB_BT_TORRENTS ." tor 
		INNER JOIN ". BB_BT_TRACKER_SNAP ." sn ON(sn.topic_id = tor.topic_id)
		INNER JOIN ". BB_FORUMS ." f ON(f.forum_id = tor.forum_id)
		INNER JOIN ". BB_TOPICS ." t ON(t.topic_id = tor.topic_id)
		WHERE tor.topic_id = $topic_id
		LIMIT 1
		");
		
switch($mode)
{	
	case 'callseed':
	$subject = sprintf ($lang['CALLSEED_SUBJECT'], $tor['topic_title']);
	$message = sprintf ($lang['CALLSEED_TEXT'], $topic_id, $tor['forum_name'], $tor['topic_title'], $tor['attach_id']);

	if($userdata['user_id'])
	{	
		if ($tor['seeders'] > 2) $this->ajax_die(sprintf($lang['CALLSEED_HAVE_SEED'], $tor['seeders']));		
		if($tor['complete_count'] == 0) $this->ajax_die($lang['CALLSEED_NOT_DOWN']);	
		if($tor['call_seed_time'] > (TIMENOW - 86400)) $this->ajax_die($lang['CALLSEED_MSG_SPAM']);
	}
	
	send_pm($tor['poster_id'], $subject, $message, $userdata['user_id']); 
	
	$sql = "UPDATE ". BB_BT_TORRENTS ." SET call_seed_time=". TIMENOW ." WHERE topic_id = $topic_id";
	if (!DB()->sql_query($sql)) $this->ajax_die($lang['CALLSEED_MSG_TIME']);
	
	$this->ajax_die($lang['CALLSEED_MSG_OK']);
	break;
}
$this->response['mode']	= $mode;